package com.hm.pagejump.slice;

import com.hm.pagejump.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.RecycleItemProvider;
import ohos.agp.components.Text;
import ohos.agp.components.element.ShapeElement;

public class MainAbilitySlice extends AbilitySlice {
    private Text text;
    private Button button;
    private int requestCode = 123;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        text = (Text)findComponentById(ResourceTable.Id_text_helloworld);
        button = (Button)findComponentById(ResourceTable.Id_button_picture_select);
        ShapeElement element = new ShapeElement();
        element.setRgbColor(new RgbColor(100,123,120));
        button.setBackground(element);
        button.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent pageJumpIntent = new Intent();
                pageJumpIntent.setParam("jump_key", "Picture Select");
                presentForResult(new PictureSelectSlice(), pageJumpIntent, requestCode);
            }
        });
    }

    @Override
    protected void onResult(int requestCode, Intent resultIntent) {
        super.onResult(requestCode, resultIntent);
        if (requestCode == this.requestCode){
            int result_value = resultIntent.getIntParam("picture_resource_id", 0);
            text.setText("Hi, result:" + result_value);
        }
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
